package site.qjdb.pojo;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;

/**
 * 	商品
 * 
 * */
public class Goods {
	private Integer gid; // 商品id
	private User user; // 发布商品的用户
	private String name; // 商品名称
	private String realPrice; // 商品真实价钱
	private Integer dbPrice; // 数据库中存储的价钱
	private String details; // 商品详情
	private Integer count; // 商品总数量
	private Integer reservedCount; // 已预约数量，对应数据库的reserved_count
	private String label; // 商品标签
	private Date time; // 商品发布时间
	private Integer isSelected; // 是否为精选商品，0：不是，1：是
	private Integer view;// 浏览量
	private Integer state; // 商品状态，0：审核中，1：已通过，2：未通过，3：已下架
	private String imgPath; // 商品图片，对应数据库的img_path

	public Goods() {
	}

	public Integer getGid() {
		return gid;
	}

	public void setGid(Integer gid) {
		this.gid = gid;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRealPrice() {
		if (this.realPrice == null && this.dbPrice != null) {
			// 从数据库获取Integer类型数据，转成String类型。目的：用于前端显示
			Double _realPrice = this.dbPrice / 100d;
			// 0.00表示保留后两位，它的处理方式是直接截掉不要的尾数，不四舍五入。
			DecimalFormat df = new DecimalFormat("0.00");
			this.realPrice = df.format(_realPrice);
		}
		return realPrice;
	}

	public void setRealPrice(String realPrice) {
		this.realPrice = realPrice;
	}

	public Integer getDbPrice() {
		if (this.dbPrice == null && this.realPrice != null) {
			// 从web端获取String类型数据，转成Integer类型。目的：1.存储到数据库 2.进行运算
			BigDecimal bigDecimal = new BigDecimal(realPrice);
			Double _realPrice = bigDecimal.setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
			Double price = _realPrice * 100;
			this.dbPrice = price.intValue();
		}
		return dbPrice;
	}

	public void setDbPrice(Integer dbPrice) {
		this.dbPrice = dbPrice;
	}

	public String getDetails() {
		return details;
	}

	public void setDetails(String details) {
		this.details = details;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Integer getReservedCount() {
		return reservedCount;
	}

	public void setReservedCount(Integer reservedCount) {
		this.reservedCount = reservedCount;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public Integer getIsSelected() {
		return isSelected;
	}

	public void setIsSelected(Integer isSelected) {
		this.isSelected = isSelected;
	}

	public Integer getView() {
		return view;
	}

	public void setView(Integer view) {
		this.view = view;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public String getImgPath() {
		return imgPath;
	}

	public void setImgPath(String imgPath) {
		this.imgPath = imgPath;
	}

	@Override
	public String toString() {
		return "Goods [gid=" + gid + ", user=" + user + ", name=" + name + ", realPrice=" + realPrice + ", dbPrice="
				+ dbPrice + ", details=" + details + ", count=" + count + ", reservedCount=" + reservedCount
				+ ", label=" + label + ", time=" + time + ", isSelected=" + isSelected + ", view=" + view + ", state="
				+ state + ", imgPath=" + imgPath + "]";
	}

}
